package com.zzb.framework.modules.mail.controller;

import com.google.common.collect.Lists;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.zzb.framework.common.BasePage;
import com.zzb.framework.common.BaseResponse;
import com.zzb.framework.common.FrameworkException;
import com.zzb.framework.modules.log.annotation.SysLog;
import com.zzb.framework.modules.mail.entity.Mail;
import com.zzb.framework.modules.mail.form.MailSearchForm;
import com.zzb.framework.modules.mail.service.MailService;
import com.zzb.framework.modules.role.controller.AbstractController;

/**
 * 事件通知方法controller
 */
@RestController
@RequestMapping("/sys/mail")
public class SysMailController extends AbstractController {
    private static final Logger logger = LoggerFactory.getLogger(SysMailController.class);
    @Autowired
    private MailService mailService;

    /**
     * 事件通知方法列表json
     */
    @GetMapping("list")
    @RequiresPermissions("sys:mail:list")
    public BasePage<Mail> list(MailSearchForm searchForm) {
        return mailService.queryPage(searchForm);
    }


    @GetMapping("info/{id}")
    @RequiresPermissions("sys:mail:info")
    public BaseResponse<Mail> info(@PathVariable String id) {
        Mail mail = mailService.get(id);
        return BaseResponse.content(mail);
    }

    /**
     * Mail方法删除
     */
    @PostMapping("/delete")
    @SysLog("删除")
    @RequiresPermissions("sys:mail:delete")
    public BaseResponse delete(@RequestBody String[] id) {
        try {
            return mailService.deleteByIds(Lists.newArrayList(id));
        } catch (FrameworkException e) {
            e.printStackTrace();
            return new BaseResponse(BaseResponse.FAIL, e.getMessage());
        }
    }

}
